extends Bullet

class_name Laser

signal laser_end

export(int) var length = 200
export(int) var laser_time = 1

onready var Ray := $RayCast2D
var _current_length := 0

var start_point : Vector2
var end_point : Vector2

func _ready():
	$Timer.wait_time = laser_time
	$Timer.start()
	Ray.enabled = true

func _phy_proc(delta):
	#called by _physics_process in Bullet class. overrided in this class
	end_point = direction.normalized() * length
	Ray.cast_to = end_point
	Ray.force_raycast_update()
	$Line2D.points = [start_point, end_point]
	if Ray.is_colliding():
		var C : Object = Ray.get_collider()
		if C is Unit:
			C.touched(self)

func _on_Timer_timeout():
	emit_signal("laser_end")
	queue_free()
